/* Yet Another Experimental Software Renderer
 *
 * Copyright (c) 2010 Pawel "Hery" Dziepak
 */

#ifndef RASTERIZER_H_
#define RASTERIZER_H_

#include "primitives.h"

#include <vector>

namespace yaesr {
	class pixel_shader;
	class output_merger;

	class rasterizer {
	public:
		rasterizer(output_merger *om) {
			Assert(om != NULL);

			next = om;
		}

		virtual void rasterize_points(std::vector<point>&) = 0;
		virtual void rasterize_lines(std::vector<line>&) = 0;
		virtual void rasterize_triangles(std::vector<triangle>&) = 0;

		void set_pixel_shader(pixel_shader *ps) {
			Assert(ps != NULL);

			pixel_sdr = ps;
		}
	protected:
		output_merger *next;
		pixel_shader *pixel_sdr;
	};

	class default_rasterizer : public rasterizer {
	public:
		default_rasterizer(output_merger *om) : rasterizer(om) { }

		void rasterize_points(std::vector<point>&);
		void rasterize_lines(std::vector<line>&);
		void rasterize_triangles(std::vector<triangle>&);

	private:
		void draw_point(vertex);
		void draw_point(int, int, vertex);

		void draw_line(vertex, vertex);

		void draw_triangle(vertex, vertex, vertex);

		vertex interpolate_line(vertex, vertex, double);
		vertex interpolate_triangle(vertex a, vertex b, vertex c, double alpha, double beta, double gamma);
	};
}

#endif